var Sequelize = require('sequelize');
var models = require('../../models');
var loginLogDao = module.exports;

loginLogDao.createLog = async function (log){
    return models.admin.AdminLoginLog.create(log);
};

loginLogDao.getLogByKeywords = async function (keywords, offset, limit) {
    var where = {};
    if (keywords && keywords.length != 0) {
        where.ip = {
            [Sequelize.Op.like]: '%'+keywords+'%'
        };
    }
    return models.admin.AdminLoginLog.findAndCountAll({
        where: where,
        order: [['login_time', 'DESC']],
        offset: Number(offset),
        limit: Number(limit),
    });
};

loginLogDao.deleteLogs = async function (pks) {
    return models.admin.AdminLoginLog.destroy({
        where: {
            id: pks
        }
    });
};